package com.aloda.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.aloda.entity.UserSuggest;
import com.aloda.query.UserSuggestPageDTO;
import com.aloda.result.PageResult;
import com.aloda.result.Result;
import com.aloda.service.UserSuggestService;
import com.aloda.vo.userSuggest.UserSuggestPageVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("suggest-admin")
@RequestMapping("/admin/suggest")
public class UserSuggestController {

    @Resource
    private UserSuggestService userSuggestService;

    /**
     * 分页查询
     * @param userSuggestPageDTO
     * @return
     */
    @PostMapping("/page")
    public Result<PageResult<UserSuggestPageVO>> pageQuery(@RequestBody UserSuggestPageDTO userSuggestPageDTO) {
        PageResult<UserSuggestPageVO> pageResult = userSuggestService.pageQuery(userSuggestPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 通过id获取
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserSuggestPageVO> getById(@PathVariable Long id) {
        UserSuggest userSuggest = userSuggestService.getById(id);
        return Result.success(BeanUtil.copyProperties(userSuggest, UserSuggestPageVO.class));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result<Boolean> delete(@RequestBody List<Long> ids) {
        return Result.success(userSuggestService.removeBatchByIds(ids));
    }
}
